﻿// JSON C# Class Generator
// http://at-my-window.blogspot.com/?page=json-class-generator

using System;
using Newtonsoft.Json.Linq;
using JsonCSharpClassGenerator;
using TomatoSynchronizer.Store;
using System.Collections;
using System.Collections.Generic;

namespace TomatoSynchronizer.Entities
{

	public class Language
	{

		public Language()
		{
		}
		
		public override bool Equals(object obj)
		{
			if(obj is Language)
			{
				Language language = (Language)obj;
				if(language._charset == _charset && language._code == _code && language._date_format_long == _date_format_long && language._date_format_short == _date_format_short && language._default == _default && language._locale == _locale && language._name == _name && language._numeric_separator_decimal == _numeric_separator_decimal && language._numeric_separator_thousands == _numeric_separator_thousands && language._text_direction == _text_direction && language._time_format == _time_format)
				{
					if(language._translationGroups.Count == _translationGroups.Count)
					{
						foreach(TranslationGroup groupSrc in language._translationGroups)
						{
							foreach(TranslationGroup groupDest in _translationGroups)
							{
								if(!groupSrc.Equals(groupDest))
								{
									return false;
								}
							}
						}
						
						return true;
					}
				}
			}
			
			return false;
		}
		
		public bool ContainsTranslation(string groupId,string definitionKey)
		{
			foreach(TranslationGroup group in _translationGroups)
			{
				foreach(Translation translation in group.Translations)
				{
					if(group.id == groupId && translation.definition_key == definitionKey)
					{
						return true;
					}
				}
			}
			
			return false;
		}				
		
		public Translation LoadTranslation(string groupId,string definitionKey)
		{
			foreach(TranslationGroup group in _translationGroups)
			{
				foreach(Translation translation in group.Translations)
				{
					if(group.id == groupId && translation.definition_key == definitionKey)
					{
						return translation;
					}
				}
			}
			
			return null;
		}
		
		private List<TranslationGroup> _translationGroups;
		public List<TranslationGroup> TranslationGroups {
			get { return _translationGroups; }
			set { _translationGroups = value; }
		}

		public Language(string json)
			: this(JObject.Parse(json))
		{
		}

		private JObject __jobject;
		public Language(JObject obj)
		{
			this.__jobject = obj;
		}

		public override int GetHashCode()
		{
			return base.GetHashCode();
		}

		private LanguageStore store;

		public LanguageStore Store
		{
			get{
				return store;}
			set{
				store = value;}
		}

		[System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
		private string _languages_id;
		public string languages_id
		{
			get
			{
				if(_languages_id == null)
					_languages_id = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "languages_id"));				
				return _languages_id;
			}
			set
			{
				_languages_id = value;
			}
		}
		
		public string Id
		{
			get
			{
				if(_languages_id == null)
					_languages_id = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "languages_id"));				
				return _languages_id;
			}
			set
			{
				_languages_id = value;
			}
		}
		
		[System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
		private string _name;
		public string name
		{
			get
			{
				if(_name == null)
					_name = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "name"));
				return _name;
			}
			set
			{
				_name = value;
			}
		}

		[System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
		private string _code;
		public string code
		{
			get
			{
				if(_code == null)
					_code = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "code"));
				return _code;
			}
			set
			{
				_code = value;
			}
		}

		[System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
		private string _locale;
		public string locale
		{
			get
			{
				if(_locale == null)
					_locale = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "locale"));
				return _locale;
			}
			set
			{
				_locale = value;
			}
		}

		[System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
		private string _charset;
		public string charset
		{
			get
			{
				if(_charset == null)
					_charset = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "charset"));
				return _charset;
			}
			set
			{
				_charset = value;
			}
		}

		[System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
		private string _date_format_short;
		public string date_format_short
		{
			get
			{
				if(_date_format_short == null)
					_date_format_short = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "date_format_short"));
				return _date_format_short;
			}
			set
			{
				_date_format_short = value;
			}
		}

		[System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
		private string _date_format_long;
		public string date_format_long
		{
			get
			{
				if(_date_format_long == null)
					_date_format_long = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "date_format_long"));
				return _date_format_long;
			}
			set
			{
				_date_format_long = value;
			}
		}

		[System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
		private string _time_format;
		public string time_format
		{
			get
			{
				if(_time_format == null)
					_time_format = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "time_format"));
				return _time_format;
			}
			set
			{
				_time_format = value;
			}
		}

		[System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
		private string _text_direction;
		public string text_direction
		{
			get
			{
				if(_text_direction == null)
					_text_direction = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "text_direction"));
				return _text_direction;
			}
			set
			{
				_text_direction = value;
			}
		}

		[System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
		private string _currencies_id;
		public string currencies_id
		{
			get
			{
				if(_currencies_id == null)
					_currencies_id = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "currencies_id"));
				return _currencies_id;
			}
			set
			{
				_currencies_id = value;
			}
		}

		[System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
		private string _numeric_separator_decimal;
		public string numeric_separator_decimal
		{
			get
			{
				if(_numeric_separator_decimal == null)
					_numeric_separator_decimal = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "numeric_separator_decimal"));
				return _numeric_separator_decimal;
			}
			set
			{
				_numeric_separator_decimal = value;
			}
		}

		[System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
		private string _numeric_separator_thousands;
		public string numeric_separator_thousands
		{
			get
			{
				if(_numeric_separator_thousands == null)
					_numeric_separator_thousands = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "numeric_separator_thousands"));
				return _numeric_separator_thousands;
			}
			set
			{
				_numeric_separator_thousands = value;
			}
		}

		[System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
		private string _parent_id;
		public string parent_id
		{
			get
			{
				if(_parent_id == null)
					_parent_id = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JValue>(__jobject, "parent_id"));
				return _parent_id;
			}
			set
			{
				_parent_id = value;
			}
		}

		[System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
		private string _sort_order;
		public string sort_order
		{
			get
			{
				if(_sort_order == null && __jobject != null)
					_sort_order = JsonClassHelper.ReadString(JsonClassHelper.GetJToken<JToken>(__jobject, "sort_order"));
				return _sort_order;
			}
			set
			{
				_sort_order = value;
			}
		}

		[System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
		private bool _default;
		public bool is_default
		{
			get
			{
				if(_default == false && __jobject != null)
					_default = JsonClassHelper.ReadBoolean(JsonClassHelper.GetJToken<JValue>(__jobject, "default"));
				return _default;
			}
			set
			{
				_default = value;
			}
		}

	}
}
